﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data.Entity;
using System.Data.Objects;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Practices.Unity;
using TraceInspector.Model;
//using Unity.AutoRegistration;
using TraceInspector.Application;

namespace TraceInspector.ViewModel
{
    public class MainWindowViewModel : ObservableObject
    {
        private IUIDataProvider _dataProvider;
        private IToolManager _toolManager;
        
       
        public MainWindowViewModel(IUIDataProvider dataProvider, IToolManager toolManager)
        {
            _dataProvider = dataProvider;
            _toolManager = toolManager;
            InitTools();
        }

        #region Properties

        public ObservableCollection<ToolViewModel> Tools
        {
            get { return _toolManager.Tools; }
        }


        private InspectionListViewModel _selectInspectionTool = null;

        public InspectionListViewModel SelectInspectionTool
        {
            get { return _selectInspectionTool; }
            set { _selectInspectionTool = value; RaisePropertyChanged("SelectInspectionTool"); }
        }

        private EditInspectionViewModel _editInspectionTool = null;

        public EditInspectionViewModel EditInspectionTool
        {
            get { return _editInspectionTool; }
            set { _editInspectionTool = value; }
        }


        #endregion

        #region Methods

        private void InitTools()
        {
            // вкладка "Выбор обследования"
            _selectInspectionTool = new InspectionListViewModel(_dataProvider, _toolManager);
            SelectInspectionTool.PropertyChanged += new PropertyChangedEventHandler(selectInspectionTool_PropertyChanged);
            _toolManager.Tools.Add(_selectInspectionTool);
            
            // редактирование обследования
            _editInspectionTool = new EditInspectionViewModel(_dataProvider, new ToolManager());
            _toolManager.Tools.Add(_editInspectionTool);
        }

        void selectInspectionTool_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if(e.PropertyName == "SelectedInspection")
            {
                _editInspectionTool.Inspection = SelectInspectionTool.SelectedInspection;
                _toolManager.SetCurrentTool(EditInspectionTool);
            }
        }

        #endregion
















    }
}
